/*
 * @Author: cqg
 * @Date: 2020-11-19 22:44:16
 * @LastEditors: cqg
 * @LastEditTime: 2020-12-22 16:34:06
 * @Description: file content
 */
import {
	getFixedWarehousing,
	doVerified
} from "@/views/wy-asset-management/verified/api/verified.js";
import assetDictionary from "@/views/wy-asset-management/mixin/assetDictionary";
import { mapGetters } from "vuex";
import { getDict } from "~/utils";
export default {
	mixins: [assetDictionary],
	data() {
		return {
			// 是否是政府项目
			government: 0,
			loading: true,
			activeName: "资产核实信息",
			//基本附件
			busId: this.$route.query.assetFixedWarehousingId,
			modelType: "asset-warehousing",
			fileList: [],
			//变更附件
			changeBusId: "",
			changeFileList: [],
			//入库附件
			wbusId: this.$route.query.warehousingAttachment,
			wfileList: [],
			//弹出框 初始时隐藏
			dialogVisible: false,
			formObj: {
				//基本信息
				roomId: "",
				assetFixedWarehousingId: this.$route.query.assetFixedWarehousingId,
				warehousingAttachment: this.$route.query.warehousingAttachment,
				assetName: "",
				assetClassification: 0,
				useStatus: 0,
				acquisitionMethod: 0,
				acquisitionDate: "",
				investmentAcquisitionDate: "",
				valueType: 0,
				registrationPrice: 0,
				registrationFee: 0,
				taxation: 0,
				value: 0,
				number: "",
				measurementUnit: 0,
				landArea: 0,
				propertyRightForm: 0,
				ownershipCertificateNo: "",
				issueData: "",
				ownershipPeriod: "",
				ownershipCertificate: 0,
				location: "",
				ownershipNature: 0,
				selfUseArea: 0,
				selfUseValue: 0,
				buildingStructure: 0,
				assetCode: "",
				voucherNo: "",
				voucherDateStart: "",
				voucherDateEnd: "",
				assetFixedWarehousingLogList: [],
				assetChangeRecordVoList: [],
				assetChangeRecordVo: {},
				changeRemarks: "",
				warehouseRemark: "",
				//变更通过状态 0 不通过 1 通过
				changeId: "",
				changeType: 0
			},
			formObj2: {
				assetCode2: "",
				voucherNo2: "",
				voucherDate: [],
				warehouseRemark: ""
			},

			//变更描述
			formObj3: {
				changeRemarks3: ""
			},

			rules3: {
				changeRemarks3: []
			}
		};
	},
	/**
	 * 载入事件
	 */
	mounted() {
		//根据主键查询已入库的信息
		this.getWarehousing();
	},
	computed: {
		...mapGetters({
			cityAssembly: "getCityAssembly",
			districtCollection: "getDistrictCollection"
		})
	},
	methods: {
		getDict(v) {
			return getDict(v);
		},
		/**
		 * 根据主键查询已入库的信息
		 */
		getWarehousing() {
			this.$route.query.assetFixedWarehousingId;
			this.loading = true;
			getFixedWarehousing(this.$route.query.assetFixedWarehousingId)
				.then(resp => {
					let obj = resp.data.data;
					this.formObj = obj;
					this.government = this.formObj.assetRegistrationId == "1" ? "1" : "0";
					this.formObj2.assetCode2 = obj.assetCode;
					this.formObj2.voucherNo2 = obj.voucherNo;
					this.formObj2.voucherDate[0] = obj.voucherDateStart;
					this.formObj2.voucherDate[1] = obj.voucherDateEnd;
					this.formObj2.warehouseRemark = obj.warehouseRemark;
				})
				.catch(error => {
					this.$message({
						type: "error",
						message: "获取信息失败"
					});
				})
				.finally(() => (this.loading = false));
		},

		//   保存按钮 触发文件上传
		sendData(val) {
			this.loading = true;
			this.formObj.changeType = val;
			this.$refs["ruleForm3"].clearValidate();
			if (!this.formObj3.changeRemarks3)
				this.formObj3.changeRemarks3 =
					this.formObj.changeType == 1 ? "审核通过" : "审核不通过";
			// this.rules3.changeRemarks3 =
			// 	this.formObj.changeType == 1
			// 		? []
			// 		: [{ required: true, message: "请输入变更信息", trigger: "blur" }];
			this.$refs.warehousingFile.submit(this.modelType);
		},
		//    保存表单信息
		saveEntity(res, file, fileList) {
			if (res.data) this.formObj.changeId = res.data;

			//资产入库
			this.formObj.assetCode = this.formObj2.assetCode2;
			this.formObj.voucherNo = this.formObj2.voucherNo2;
			this.formObj.voucherDateStart = this.formObj2.voucherDate[0];
			this.formObj.voucherDateEnd = this.formObj2.voucherDate[1];
			this.formObj.changeRemarks = this.formObj3.changeRemarks3;
			doVerified(this.formObj)
				.then(data => {
					this.$message({
						type: "success",
						message: "操作成功"
					});
					//操作完成 跳转页面
					this.$router.push("/asset-management/verified-list");
				})
				.catch(error => {
					this.$message({
						type: "error",
						message: "操作失败"
					});
				})
				.finally(() => (this.loading = false));
		}
	}
};
